package com.manfred.uddi.test;

import java.util.Vector;

import org.uddi4j.client.UDDIProxy;
import org.uddi4j.datatype.Name;
import org.uddi4j.response.AuthToken;
import org.uddi4j.response.BusinessInfo;
import org.uddi4j.response.BusinessList;
import org.uddi4j.transport.TransportFactory;
import org.uddi4j.util.FindQualifier;
import org.uddi4j.util.FindQualifiers;

public class FindBusiness {

	public static void main(String args[]) {
		// String inquiryURL = "http://localhost:8080/juddi/inquiry";
		// String publishURL = "http://localhost:8080/juddi/publish";
		String inquiryURL = "http://localhost:8080/juddiv3/services/inquiryv2";
		String publishURL = "http://localhost:8080/juddiv3/services/publishv2";
		String userId = "juddi";
		String credential = "juddi";

		String transportClass = "org.uddi4j.transport.ApacheAxisTransport";
		System.setProperty(TransportFactory.PROPERTY_NAME, transportClass);

		UDDIProxy proxy = new UDDIProxy();

		try {

			proxy.setInquiryURL(inquiryURL);
			proxy.setPublishURL(publishURL);

			AuthToken token = proxy.get_authToken(userId, credential);
			System.out.println("Security authToken:"
					+ token.getAuthInfoString());

			String businessToFind = "The Daily Moon";
			Vector names = new Vector();
			names.add(new Name(businessToFind));

			FindQualifiers findQualifiers = new FindQualifiers();
			Vector qualifier = new Vector();
			qualifier.add(new FindQualifier("exactNameMatch"));
			findQualifiers.setFindQualifierVector(qualifier);
			BusinessList businessList = proxy.find_business(names, null, null,
					null, null, findQualifiers, 5);

			Vector businessInfoVector = businessList.getBusinessInfos()
					.getBusinessInfoVector();
			for (int i = 0; i < businessInfoVector.size(); i++) {
				BusinessInfo businessInfo = (BusinessInfo) businessInfoVector
						.elementAt(i);
				System.out.println(businessInfo.getDefaultNameString() + ": "
						+ businessInfo.getBusinessKey());
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}